Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ExcludeKey option to TextFormatter #1433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ningyougang
Copy link

@ningyougang ningyougang commented May 15, 2024

  • Add ExcludeKey option to TextFormatter
  • AS-IS (ExcludeKey : false, this is default)

    time="2024-05-14T16:47:03+09:00" level=warning msg="message"
    
  • TO-BE (after applied ExcludeKey : true)

    2024-05-14T16:47:03+09:00 warning message
    

I think this is a common case, when some log collector agent collect the logs from file or standard output, does not need the startingKey(e.g. time=)

@ningyougang ningyougang force-pushed the add-exclude-key-option branch from cd432c8 to aedfb7c Compare May 15, 2024 00:27
@@ -331,9 +337,14 @@ func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
stringVal = fmt.Sprint(value)
}

if !f.needsQuoting(stringVal) {
// write value without quoting directly when ExcludeKey is true
if f.ExcludeKey {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If configure ExcludeKey as true, just write value without quoting directly, otherwise, the logs will be as below

"0001-01-01T00:00:00Z" warning "message"

@ningyougang ningyougang force-pushed the add-exclude-key-option branch from aedfb7c to a886e5b Compare May 15, 2024 00:31
b.WriteString(stringVal)
} else {
b.WriteString(fmt.Sprintf("%q", stringVal))
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the same logic as before when ExcludeKey is false(this is default)

@ningyougang
Copy link
Author

Can someone review this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants